﻿<?php
	//ob_start('compress_page');
	require_once(CONTROLLER_DIR.'/template/header_page.phtml');
	require_once('cart_seo.phtml');
?>
<body>
	
	<div id="wrapper">
		<?php	require_once(CONTROLLER_DIR.'/template/header.phtml'); ?>	
		<div id="content" > 
			<div id="news-id" class="news-detail">
				
				<?php
					if($cartProduct)
					{
						echo "<h2 style='margin-left:25px;color: #fff'> GIỎ HÀNG CỦA BẠN</h2>";
						echo "<table class='checkout-table ' cellpadding='0' cellspacing='0'>
								<thead>
									<tr class='headings'>
										<th class='h_products' colspan='2'><span>SẢN PHẨM</span></th>
										<th class='h_price' ><span>GIÁ (VNĐ)</span></th>
										<th class='h_quantity' ><span>SL</th>
										<th class='h_total' ><span>TỔNG</span></th>
									</tr>
								</thead>
								<tbody>";
						$sum = 0;
						foreach($cartProduct as $value)
						{
							echo "<tr class='cart-item-rows'>";
							if($value['product_refer_img'])
								echo "<td class='thumb'><a ><img src='{$value['product_refer_img']}' class='border'></a></td>";
							else
								echo "<td class='thumb'><a ><img src='{$value['product_img1']}' class='border'></a></td>";
								
							echo "<td class='name'><div class='product-info'><h4>";
							echo 	"<span class='name'><a >{$value['product_name']}</a></span></h4>";
							echo	"<span class='size'>{$value['product_refer_name']}</span></div>";
							echo	"<br/><a href='cart.php?action=remove&id={$value['product_refer_id']}'id='remove_3186' class='remove_link' >Xoá</a></td>";
							
							$price = FormatPrice($value['product_refer_price']);
							$priceSale = FormatPrice($value['product_refer_price_sale']);
							
							if($value['product_refer_price_sale'] > 0)
							{	
								echo "	<td class='price'><strike>$price</strike><br/><a>$priceSale</a>
										</td>";
							}
							else
								echo "	<td class='price'>$price</td>";
								
							echo "<td class='qty'><select id='{$value['product_refer_id']}-qty'>";
							//{$value['quantity']}
								for($i=1;$i<=5;$i++)
								{
									if($i == $value['quantity'])
										echo "<option selected='selected'>$i</option>";
									else
										echo "<option >$i</option>";
								}
							echo "</select></td>";
							
							echo "<td class='total'>".FormatPrice($value['total'])."</td>";
							echo "</tr>";
							$sum+=$value['total'];
						}
						
						echo "</tbody>
								<tfoot>
									<tr class='subtotal-row'>
										<td colspan='3'>&nbsp;</td>
										<td colspan='2' class='cart_subtotal'>
											<div class='totals_container'>
												<div class='row total_row'>
													<span class='label'>Tổng</span><span class='value'>".FormatPrice($sum)."</span>
												</div>
											</div>
										</td>
									</tr>
								</tfoot>
							</table>		";
						echo "<form id='form-cart' style='margin-bottom: 30px'>
								<table>
									<tbody><tr>
										<td width='80px' style='text-align:right'>Họ và tên</td>
										<td width='310px'><input type='text' id='form-name' name='form-name' style='width:200px'>(<span class='mark'>*</span>)</td>
									</tr>
									<tr>
										<td width='80px' style='text-align:right'>Điện thoại</td>
										<td width='310px'><input type='text' id='form-phone' name='form-phone' style='width:200px'>(<span class='mark'>*</span>)</td>
									</tr>
									<tr>
										<td width='80px' style='text-align:right'>Email</td>
										<td width='310px'><input type='text' id='form-email' name='form-email' style='width:200px'></td>
									</tr>
									<tr>
										<td width='80px' style='text-align:right'>Địa chỉ</td>
										<td width='320px'><input placeholder='Địa chỉ nhận hàng của bạn' type='text' id='form-addr' name='form-addr' style='width:304px'>(<span class='mark'>*</span>)</td>
									</tr>
									<tr>
										<td width='80px' style='text-align:right'>Ghi chú</td>
										<td width='320px'><textarea id='form-note' style='width:300px;height:50px' name='form-note'></textarea></td>
									</tr>
									<tr>
										<td width='80px' style='text-align:right'></td>
										<td width='310px'>(<span class='mark'>*</span>)<em> Nội dung không được để trống</em></td>
									</tr>
									<tr>
										<td width='80px' style='text-align:right'></td>
										<td width='310px' ><br><a onclick='javascript: return sendCart()' class='btn btn-primary' style='color:#fff'>Gởi đơn hàng</a></td>
									</tr>
								</tbody></table>
								<input type='hidden' name='form-type' value='cart'>
								<input type='hidden' name='form-total' value='$sum'>
							</form>";
					}
					else
						echo "<h2 style='margin-left:25px;color: #fff'> GIỎ HÀNG CỦA BẠN ĐANG TRỐNG</h2>";
				?>
<script>
	$("select").change(function () 
	{
          var id = parseInt($(this).attr('id'));
		  var qty = '';
          $("#"+id+"-qty option:selected").each(function () {
                qty = parseInt($(this).text());
              });
          window.open('/cart.php?action=change&id='+id+'&qty='+qty,'_self');
		  //$("div").text(str);
    });	
	function sendCart()
	{
		var name = $('#form-name').attr('value');
		var phone = $('#form-phone').attr('value');
		var addr = $('#form-addr').attr('value');
		
		if(name =='' || phone=='' || addr=='') 
			alert('Nhập thiếu thông tin bắt buộc');
		else
		{
			$.post("ajax/order.php", $("#form-cart").serialize(),function(data)
			{
				alert(data);
				window.open('/','_self');
			});
		}
	}
</script>			
			</div>

			
			<div id='content-right' style='float:left;'>
				<?php	
					require_once(CONTROLLER_DIR.'/template/wholesale/wholesale.php'); 
					require_once(CONTROLLER_DIR.'/template/ticker/ticker.php'); 
				?>	
			</div>
			<div class="spacer"></div>
		</div><!--id: content-->
		<?php require_once(CONTROLLER_DIR.'/template/poster/poster.php'); ?>	
		<?php require_once(CONTROLLER_DIR.'/template/footer.phtml'); ?>	
	</div><!--id: wrapper-->
</body>
</html>
<?php	
	/*  end the buffer, echo the page content  */
	//ob_end_flush();
?>	
